<?php

namespace App\Http\Controllers;

use App\Checklist;
use Illuminate\Support\Str;

class LnksController extends Controller
{
    public function show()
    {
        $checklist = $this->listData();
        if(!$checklist) {
            return abort(404);
        }

        return view('checklists.show', [
            'checklist' => $checklist
        ]);
    }

    public function listData() {
        // 修改为一个项目只有一个清单列表所有人共享
        $listname = "";
        $list = Checklist::first();
        if ($list) {
            $listname=$list->hash;
        } else {
            $checklist = Checklist::create([
                'hash' => Str::random(32)
            ]);
            $listname=$checklist->hash;
        }

        // 查询清单列表下的所有任务数据
        $checklist = Checklist::where('hash', $listname)
            ->with(['items'])
            ->first();
        return $checklist;
    }
}

